package ru.spb.osll.myfit.util;

import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import junit.framework.TestCase;

import org.junit.Test;

public class StringUtilsTest extends TestCase {

	@Test
	public void testJoin() {
		assertEquals("", StringUtils.join(new LinkedList<String>(), "."));
		assertEquals("a", StringUtils.join(CollectionUtils.list("a"), "."));
		assertEquals("a.b", StringUtils.join(CollectionUtils.list("a", "b"),
				"."));
		assertEquals("a,b,c", StringUtils.join(CollectionUtils.list("a", "b",
				"c"), ","));
	}

	@Test
	public void testSplitCamelCase() {
		HashMap<String, String> map = new HashMap<String, String>();

		map.put("WriteWithCubetoolsFixture", "Write with cubetools fixture");
		map.put("VerifyDeleteWithCubetoolsUsingFixture",
				"Verify delete with cubetools using fixture");
		map.put("DeleteClipsWithCubetoolsUsingFixture",
				"Delete clips with cubetools using fixture");

		Iterator<Entry<String, String>> iter = map.entrySet().iterator();

		while (iter.hasNext()) {
			Entry<String, String> cur = iter.next();
			assertEquals(StringUtils.splitCamelCase(cur.getKey()), cur
					.getValue());
		}
	}

	@Test
	public void testSubstringFromPattern() {
		Date now = new Date();
		String time = FileHelper.DATE_FORMATTER.format(now);
		String name = "something_page_name";
		String id = name + FileHelper.SEPARATOR + time;

		String firstPart = StringUtils.substringFromPattern(FileHelper.FORMAT_PATTERN, id, 1);
		String secondPart = StringUtils.substringFromPattern(FileHelper.FORMAT_PATTERN, id, 2);

		assertEquals(firstPart, name);
		assertEquals(secondPart, time);
	}
}
